
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
        <title>
            微信支付
        </title>

    </head>
    <body>

    </body>
    <script type="text/javascript" src="/static/api/js/jquery-3.5.1.min.js"></script>
    <script>
        var pay_order_number = "{$pay_order_number}"
        var openid = "{$openid}"
        $.post('/BoxRechargePay/wxCodePay',{pay_order_number:pay_order_number,openid:openid},function (req) {
            function jsApiCall() {
                var  data = req;
                console.log(data);
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',
                    data,
                    function (res) {
                        switch (res.err_msg){
                            case 'get_brand_wcpay_request:cancel':
                                alert("取消支付");
                                window.history.back(-1);
                                break;
                            case 'get_brand_wcpay_request:fail':
                                alert("支付失败");
                                window.history.back(-1);
                                break;
                            case 'get_brand_wcpay_request:ok':
                                alert("支付成功");
                                // window.history.back(-1);
                                window.location.href="{$pay_success_html}";
                                break;
                        }
                        WeixinJSBridge.log(res.err_msg);
                        //alert(res.err_code+res.err_desc+res.err_msg);
                        // if (res.err_msg == "get_brand_wcpay_request:ok") {
                        //     window.history.back(-1);
                        // }
                    }
                );
            };

            function callpay() {
                if (typeof WeixinJSBridge == "undefined") {
                    if (document.addEventListener) {
                        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                    } else if (document.attachEvent) {
                        document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                    }
                } else {
                    jsApiCall();
                }
            };
            callpay();
        });
    </script>
</html>
